home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / title.cl_ / title.cl
Text File  |  1995-03-12  |  5KB  |  145 lines

  1. Version 1.0 Class
  2. Attribute VB_Name = "clsTitle"
  3. Attribute VB_Creatable = True
  4. Attribute VB_Exposed = True
  5. Option Explicit
  6.  
  7. Private m_Database As String
  8. Private m_Title As String
  9. Private m_ISBN As String
  10. Private m_PublisherID As Long
  11. Private m_PublisherName As String
  12. Private m_Year As Integer
  13. Private m_Description As String
  14. Private m_Notes As String
  15. Private m_Subject As String
  16. Private m_Comments As String
  17.  
  18. Property Let DatabaseName(theDatabase As String)
  19.     m_Database = theDatabase
  20. End Property
  21. Property Let Title(theTitle As String)
  22.     m_Title = theTitle
  23. End Property
  24. Property Let ISBN(theISBN As String)
  25.     m_ISBN = theISBN
  26. End Property
  27. Property Let PublisherID(thePublisher As Long)
  28.     On Error GoTo LetPubIDError
  29.     m_PublisherID = thePublisher
  30.     ReadPublisherName
  31. Exit Property
  32. LetPubIDError:
  33.     If Err.Number = ERR_CANTFINDRECORD Then
  34.         LastError = ERR_INVALIDPUBLISHERID
  35.     Else
  36.         LastError = Err.Number
  37.     End If
  38.     ErrorHandler vbExclamation
  39. End Property
  40. Property Let PublisherName(theName As String)
  41.     ' Calling routine must handle errors
  42.     ReadPublisherName theName
  43. End Property
  44. Property Let YearPublished(theYear As Integer)
  45.     m_Year = theYear
  46. End Property
  47. Property Let Subject(theSubject As String)
  48.     m_Subject = theSubject
  49. End Property
  50. Property Let Description(theDescription As String)
  51.     m_Description = theDescription
  52. End Property
  53. Property Let Comments(theComments As String)
  54.     m_Comments = theComments
  55. End Property
  56. Property Let Notes(theNotes As String)
  57.     m_Notes = theNotes
  58. End Property
  59. Property Get DatabaseName() As String
  60.     DatabaseName = m_Database
  61. End Property
  62. Property Get Title() As String
  63.     Title = m_Title
  64. End Property
  65. Property Get ISBN() As String
  66.     ISBN = m_ISBN
  67. End Property
  68. Property Get PublisherID() As Long
  69.     PublisherID = m_PublisherID
  70. End Property
  71. Property Get PublisherName() As String
  72.     PublisherName = m_PublisherName
  73. End Property
  74. Property Get YearPublished() As Integer
  75.     YearPublished = m_Year
  76. End Property
  77. Property Get Subject() As String
  78.     Subject = m_Subject
  79. End Property
  80. Property Get Description() As String
  81.     Description = m_Description
  82. End Property
  83. Property Get Comments() As String
  84.     Comments = m_Comments
  85. End Property
  86. Property Get Notes() As String
  87.     Notes = m_Notes
  88. End Property
  89.  
  90. Private Sub ReadPublisherName(Optional theName As Variant)
  91.     ' Calling routine must handle errors
  92.     Dim db As Database
  93.     Dim rs As Recordset
  94.     Dim sql As String
  95.     
  96.     If m_PublisherID < 1 Then Err.Raise ERR_OBJECTNOTINITIALIZED
  97.     
  98.     Set db = DBEngine.Workspaces(0).OpenDatabase(m_Database, False, True)
  99.     sql = "SELECT [PubID], [Name] FROM Publishers "
  100.     If VarType(theName) = vbString Then
  101.         sql = sql & " WHERE [Name] = '" & theName & "'"
  102.     Else
  103.         sql = sql & " WHERE [PubID] = " & m_PublisherID
  104.     End If
  105.     
  106.     Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
  107.     If rs.RecordCount = 0 Then Err.Raise ERR_CANTFINDRECORD
  108.     rs.MoveLast
  109.     If rs.RecordCount > 1 Then Err.Raise ERR_TOOMANYRECORDS
  110.     
  111.     m_PublisherName = rs![Name]
  112.     m_PublisherID = rs![PubID]
  113.  
  114. End Sub
  115. Public Sub Initialize(rs As Recordset, Optional theDatabaseName As Variant)
  116.     Dim db As Database
  117.     Dim tbl As Recordset
  118.     
  119.     If Not IsMissing(theDatabaseName) Then m_Database = theDatabaseName
  120.     If m_Database = "" Then Err.Raise ERR_DATABASENOTSPECIFIED
  121.  
  122.     m_ISBN = rs![ISBN]
  123.     If Not IsNull(rs![Title]) Then m_Title = rs![Title] Else m_Title = ""
  124.     If Not IsNull(rs![PubID]) Then m_PublisherID = rs![PubID] Else m_PublisherID = 0
  125.     If Not IsNull(rs![Year Published]) Then m_Year = rs![Year Published] Else m_Year = 0
  126.     If Not IsNull(rs![Subject]) Then m_Subject = rs![Subject] Else m_Subject = ""
  127.     If Not IsNull(rs![Description]) Then m_Description = rs![Description] Else m_Description = ""
  128.     If Not IsNull(rs![Notes]) Then m_Notes = rs![Notes] Else m_Notes = ""
  129.     If Not IsNull(rs![Comments]) Then m_Comments = rs![Comments] Else m_Comments = ""
  130.     If m_PublisherID <> 0 Then
  131.         Set db = DBEngine.Workspaces(0).OpenDatabase(m_Database)
  132.         Set tbl = db.OpenRecordset("Publishers")
  133.         tbl.Index = "PrimaryKey"
  134.         tbl.Seek "=", m_PublisherID
  135.         If Not rs.NoMatch Then
  136.             If Not IsNull(tbl![Name]) Then m_PublisherName = tbl![Name] Else m_PublisherName = ""
  137.         Else
  138.             m_PublisherName = ""
  139.         End If
  140.     Else
  141.          m_PublisherName = ""
  142.     End If
  143.         
  144. End Sub
  145.